#include "sales.h"
#include <iostream>

using namespace SALES;


SALES::Sales::Sales(const double ar[], int n)
{
	int len = n < QUARTERS ? n : QUARTERS;
	double sum = 0.0;
	for (int i = 0; i < len; i++)
	{
		this->sales[i] = ar[i];
		sum += this->sales[i];
	}
	this->max = this->sales[0];
	this->min = this->sales[0];

	for (int i = 1; i < len; i++)
	{
		if (this->max < this->sales[i])this->max = this->sales[i];
		if (this->min > this->sales[i])this->min = this->sales[i];
	}
	this->average = sum / len;
}
SALES::Sales::Sales()
{
	double sum = 0.0;
	for (int i = 0; i < QUARTERS; i++)
	{
		std::cin >> this->sales[i];
		sum += this->sales[i];
	}
	this->max = this->min = this->sales[0];
	for (int i = 1; i < QUARTERS; i++)
	{
		if (this->max < this->sales[i])this->max = this->sales[i];
		if (this->min > this->sales[i])this->min = this->sales[i];
	}
	this->average = sum / QUARTERS;
}
void SALES::Sales::showSales()const
{
	for (int i = 0; i < QUARTERS; i++)
	{
		std::cout << this->sales[i] << " ";
	}
	std::cout << std::endl;
	std::cout << "max:" << this->max << std::endl;
	std::cout << "min:" << this->min << std::endl;
	std::cout << "average:" << this->average << std::endl;
}


//void SALES::setSales(Sales& s, const double ar[], int n)
//{
//	int len = n < QUARTERS ? n : QUARTERS;
//	double sum = 0.0;
//	for (int i = 0; i < len; i++)
//	{
//		s.sales[i] = ar[i];
//		sum += s.sales[i];
//	}
//	s.max = s.sales[0];
//	s.min = s.sales[0];
//
//	for (int i = 1; i < len; i++)
//	{
//		if (s.max < s.sales[i])s.max = s.sales[i];
//		if (s.min > s.sales[i])s.min = s.sales[i];
//	}
//	s.average = sum / len;
//}

//void SALES::setSales(Sales& s)
//{
//	double sum = 0.0;
//	for (int i = 0; i < QUARTERS; i++)
//	{
//		std::cin >> s.sales[i];
//		sum += s.sales[i];
//	}
//	s.max = s.min = s.sales[0];
//	for (int i = 1; i < QUARTERS; i++)
//	{
//		if (s.max < s.sales[i])s.max = s.sales[i];
//		if (s.min > s.sales[i])s.min = s.sales[i];
//	}
//	s.average = sum / QUARTERS;
//}

//void SALES::showSales(const Sales& s)
//{
//	for (int i = 0; i < QUARTERS; i++)
//	{
//		std::cout << s.sales[i] << " ";
//	}
//	std::cout << std::endl;
//	std::cout << "max:" << s.max << std::endl;
//	std::cout << "min:" << s.min << std::endl;
//	std::cout << "average:" << s.average << std::endl;
//}


